<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>viper操作文档 | anyang的博客</title>
    <meta name="description" content="千里之行,始于足下">
    <meta name="generator" content="VuePress 1.3.1">
    <link rel="icon" href="/img/favicon.ico">
  <script charset="utf-8" src="/js/main.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.2/jquery.fancybox.min.css">
  <meta name="keywords" content="福小林,奔奔,ourLang,CentOS,JAVA,vue组件,lsdCloud">
  <script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-146891701-1"></script>
  <script>window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-146891701-1');</script>
  <script>var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?56eae8eec590ccaef1d5ff99d766f315";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })();</script>
    
    <link rel="preload" href="/assets/css/0.styles.9fff9873.css" as="style"><link rel="preload" href="/assets/js/app.1bc80adb.js" as="script"><link rel="preload" href="/assets/js/2.7c0608ab.js" as="script"><link rel="preload" href="/assets/js/93.cf5ff33c.js" as="script"><link rel="prefetch" href="/assets/js/10.81caa2ab.js"><link rel="prefetch" href="/assets/js/100.05bb269d.js"><link rel="prefetch" href="/assets/js/101.3e18b4d6.js"><link rel="prefetch" href="/assets/js/102.c7d7ed9c.js"><link rel="prefetch" href="/assets/js/103.4c771ce7.js"><link rel="prefetch" href="/assets/js/104.a2acd367.js"><link rel="prefetch" href="/assets/js/105.63399350.js"><link rel="prefetch" href="/assets/js/106.8a4744cc.js"><link rel="prefetch" href="/assets/js/107.7739d796.js"><link rel="prefetch" href="/assets/js/108.8008ae33.js"><link rel="prefetch" href="/assets/js/109.01c63898.js"><link rel="prefetch" href="/assets/js/11.7b837560.js"><link rel="prefetch" href="/assets/js/110.ad01aca9.js"><link rel="prefetch" href="/assets/js/111.3d74db70.js"><link rel="prefetch" href="/assets/js/112.67f55c34.js"><link rel="prefetch" href="/assets/js/113.016cd3c0.js"><link rel="prefetch" href="/assets/js/114.860e4b2b.js"><link rel="prefetch" href="/assets/js/115.b2f26258.js"><link rel="prefetch" href="/assets/js/116.8bea67b4.js"><link rel="prefetch" href="/assets/js/117.20682843.js"><link rel="prefetch" href="/assets/js/118.86a22e16.js"><link rel="prefetch" href="/assets/js/119.ad518bea.js"><link rel="prefetch" href="/assets/js/12.8fd78714.js"><link rel="prefetch" href="/assets/js/120.f97dd86f.js"><link rel="prefetch" href="/assets/js/121.c5601b4a.js"><link rel="prefetch" href="/assets/js/122.2889645a.js"><link rel="prefetch" href="/assets/js/13.ebf26820.js"><link rel="prefetch" href="/assets/js/14.b92dca09.js"><link rel="prefetch" href="/assets/js/15.b3dcef45.js"><link rel="prefetch" href="/assets/js/16.50378990.js"><link rel="prefetch" href="/assets/js/17.056bba2b.js"><link rel="prefetch" href="/assets/js/18.9047bb38.js"><link rel="prefetch" href="/assets/js/19.ab53b0fe.js"><link rel="prefetch" href="/assets/js/20.fe0b8af0.js"><link rel="prefetch" href="/assets/js/21.20a702f3.js"><link rel="prefetch" href="/assets/js/22.0ee08d29.js"><link rel="prefetch" href="/assets/js/23.02039a9a.js"><link rel="prefetch" href="/assets/js/24.363d3d74.js"><link rel="prefetch" href="/assets/js/25.dd6b101e.js"><link rel="prefetch" href="/assets/js/26.20493714.js"><link rel="prefetch" href="/assets/js/27.708723e5.js"><link rel="prefetch" href="/assets/js/28.4561834a.js"><link rel="prefetch" href="/assets/js/29.15cfcf5f.js"><link rel="prefetch" href="/assets/js/3.8d39d40c.js"><link rel="prefetch" href="/assets/js/30.04ab69de.js"><link rel="prefetch" href="/assets/js/31.b11c4302.js"><link rel="prefetch" href="/assets/js/32.81ae74ee.js"><link rel="prefetch" href="/assets/js/33.ddf09cc0.js"><link rel="prefetch" href="/assets/js/34.bc3549f7.js"><link rel="prefetch" href="/assets/js/35.4a0e0ebd.js"><link rel="prefetch" href="/assets/js/36.961a1c50.js"><link rel="prefetch" href="/assets/js/37.d8658de5.js"><link rel="prefetch" href="/assets/js/38.f76063aa.js"><link rel="prefetch" href="/assets/js/39.73edd08f.js"><link rel="prefetch" href="/assets/js/4.916af9bf.js"><link rel="prefetch" href="/assets/js/40.72314bff.js"><link rel="prefetch" href="/assets/js/41.c5eb1147.js"><link rel="prefetch" href="/assets/js/42.07aeafbb.js"><link rel="prefetch" href="/assets/js/43.c4a652ba.js"><link rel="prefetch" href="/assets/js/44.91fbe22b.js"><link rel="prefetch" href="/assets/js/45.6eecf0c4.js"><link rel="prefetch" href="/assets/js/46.81b7f108.js"><link rel="prefetch" href="/assets/js/47.b4468ab3.js"><link rel="prefetch" href="/assets/js/48.df205f23.js"><link rel="prefetch" href="/assets/js/49.7df59fa3.js"><link rel="prefetch" href="/assets/js/5.4fcd540a.js"><link rel="prefetch" href="/assets/js/50.0dc2fc5b.js"><link rel="prefetch" href="/assets/js/51.1ffabe54.js"><link rel="prefetch" href="/assets/js/52.2269d284.js"><link rel="prefetch" href="/assets/js/53.81b23843.js"><link rel="prefetch" href="/assets/js/54.b3249def.js"><link rel="prefetch" href="/assets/js/55.50dcf2af.js"><link rel="prefetch" href="/assets/js/56.c399c272.js"><link rel="prefetch" href="/assets/js/57.024f1dbb.js"><link rel="prefetch" href="/assets/js/58.680c6cf4.js"><link rel="prefetch" href="/assets/js/59.2291e9d7.js"><link rel="prefetch" href="/assets/js/6.7610d1d4.js"><link rel="prefetch" href="/assets/js/60.e59a26c1.js"><link rel="prefetch" href="/assets/js/61.ff5c64e4.js"><link rel="prefetch" href="/assets/js/62.7d97062c.js"><link rel="prefetch" href="/assets/js/63.6456dc7e.js"><link rel="prefetch" href="/assets/js/64.0b055680.js"><link rel="prefetch" href="/assets/js/65.9f25601c.js"><link rel="prefetch" href="/assets/js/66.cd973084.js"><link rel="prefetch" href="/assets/js/67.9b8f9716.js"><link rel="prefetch" href="/assets/js/68.d6c1869a.js"><link rel="prefetch" href="/assets/js/69.0a3688dd.js"><link rel="prefetch" href="/assets/js/7.9ebbd956.js"><link rel="prefetch" href="/assets/js/70.22f48891.js"><link rel="prefetch" href="/assets/js/71.9eb4fda9.js"><link rel="prefetch" href="/assets/js/72.ca4fa80c.js"><link rel="prefetch" href="/assets/js/73.17d1ab37.js"><link rel="prefetch" href="/assets/js/74.139691db.js"><link rel="prefetch" href="/assets/js/75.08d0560f.js"><link rel="prefetch" href="/assets/js/76.61078c10.js"><link rel="prefetch" href="/assets/js/77.4482adcc.js"><link rel="prefetch" href="/assets/js/78.166f2c37.js"><link rel="prefetch" href="/assets/js/79.2c7d6b79.js"><link rel="prefetch" href="/assets/js/8.6f8916c2.js"><link rel="prefetch" href="/assets/js/80.80445c3f.js"><link rel="prefetch" href="/assets/js/81.14e3bae8.js"><link rel="prefetch" href="/assets/js/82.7dac687f.js"><link rel="prefetch" href="/assets/js/83.1dd2e78e.js"><link rel="prefetch" href="/assets/js/84.23b759de.js"><link rel="prefetch" href="/assets/js/85.7574f69f.js"><link rel="prefetch" href="/assets/js/86.102dac61.js"><link rel="prefetch" href="/assets/js/87.8f5d639e.js"><link rel="prefetch" href="/assets/js/88.e564cbbe.js"><link rel="prefetch" href="/assets/js/89.cd66eb78.js"><link rel="prefetch" href="/assets/js/9.baa162db.js"><link rel="prefetch" href="/assets/js/90.685c6878.js"><link rel="prefetch" href="/assets/js/91.b8d1b7ea.js"><link rel="prefetch" href="/assets/js/92.1faa374d.js"><link rel="prefetch" href="/assets/js/94.8a02aefb.js"><link rel="prefetch" href="/assets/js/95.1b379a5b.js"><link rel="prefetch" href="/assets/js/96.9fd67185.js"><link rel="prefetch" href="/assets/js/97.c5a6a5a1.js"><link rel="prefetch" href="/assets/js/98.9a231411.js"><link rel="prefetch" href="/assets/js/99.5b344cab.js">
    <link rel="stylesheet" href="/assets/css/0.styles.9fff9873.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">anyang的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/study-guide/introduction.html" class="nav-link">
  学习指南
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术分类" class="dropdown-title"><span class="title">技术分类</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/java/introduction.html" class="nav-link">
  Java
</a></li><li class="dropdown-item"><!----> <a href="/go/introduction.html" class="nav-link">
  Go
</a></li><li class="dropdown-item"><!----> <a href="/sql/introduction.html" class="nav-link">
  SQL
</a></li><li class="dropdown-item"><!----> <a href="/fhir/introduction.html" class="nav-link">
  FHIR
</a></li></ul></div></div><div class="nav-item"><a href="/blog/introduction.html" class="nav-link">
  个人博客
</a></div><div class="nav-item"><a href="/tool/developmentBox.html" class="nav-link">
  开发百宝箱
</a></div><div class="nav-item"><a href="/project/introduction.html" class="nav-link">
  项目分享
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="了解更多" class="dropdown-title"><span class="title">了解更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1300378587&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  其他合作
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="http://www.lsdcloud.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  友情网站
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://github.com/ourlang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/anlexanyang" target="_blank" rel="noopener noreferrer" class="nav-link external">
  码云
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://blog.csdn.net/qq_37493556" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="/linkExchanges/introduction.html" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/go/introduction.html" class="sidebar-link">Go语言</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go教程</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Go Web框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Go工具中间件</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/go/middleware/go-coding-standard.html" class="sidebar-link">Golang语言编码规范</a></li><li><a href="/go/middleware/go-get命令详解.html" class="sidebar-link">go get命令详解</a></li><li><a href="/go/middleware/go-mysql.html" class="sidebar-link">Go语言操作Mysql</a></li><li><a href="/go/middleware/go-redis.html" class="sidebar-link">go-redis文档</a></li><li><a href="/go/middleware/go-swagger.html" class="sidebar-link">go-swagger安装及使用</a></li><li><a href="/go/middleware/go-viper.html" class="active sidebar-link">viper操作文档</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_1-viper简单介绍" class="sidebar-link">1 Viper简单介绍</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_1-1-什么是viper" class="sidebar-link">1.1 什么是Viper</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_1-2-为何选择viper" class="sidebar-link">1.2 为何选择Viper</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_1-3-配置方式的优先级顺序" class="sidebar-link">1.3 配置方式的优先级顺序</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-安装及使用" class="sidebar-link">2 安装及使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-1-安装依赖" class="sidebar-link">2.1 安装依赖</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-2-设置默认值" class="sidebar-link">2.2 设置默认值</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-3-读取配置文件" class="sidebar-link">2.3 读取配置文件</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-4-监听并重新读取配置文件" class="sidebar-link">2.4 监听并重新读取配置文件</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-5-从io-reader读取配置" class="sidebar-link">2.5 从io.Reader读取配置</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-6-设置并覆盖配置值" class="sidebar-link">2.6 设置并覆盖配置值</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-7-注册和使用别名" class="sidebar-link">2.7 注册和使用别名</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-8-使用环境变量" class="sidebar-link">2.8 使用环境变量</a></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_2-9-远程key-value存储" class="sidebar-link">2.9 远程key/value存储</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_3-viper获取值" class="sidebar-link">3 Viper获取值</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_3-1-访问嵌套数据" class="sidebar-link">3.1 访问嵌套数据</a></li></ul></li><li class="sidebar-sub-header"><a href="/go/middleware/go-viper.html#_4-更多参考资料" class="sidebar-link">4 更多参考资料</a></li></ul></li><li><a href="/go/middleware/Goland的自定义快捷键配置.html" class="sidebar-link">配置Goland的自定义快捷键</a></li><li><a href="/go/middleware/Golang的安装配置golint.html" class="sidebar-link">Golang的安装配置golint</a></li><li><a href="/go/middleware/goproxy.html" class="sidebar-link">GoLand配置GOPROXY代理</a></li><li><a href="/go/middleware/gorm.html" class="sidebar-link">GORM基本操作</a></li><li><a href="/go/middleware/json-iterator.html" class="sidebar-link">json-iterator使用</a></li><li><a href="/go/middleware/package.html" class="sidebar-link">Go语言包和包管理</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="viper操作文档"><a href="#viper操作文档" class="header-anchor">#</a> viper操作文档</h1> <p><a data-fancybox="" title="go-viper" href="/img/goImage/go-viper.png"><img src="/img/goImage/go-viper.png" alt="go-viper"></a></p> <h2 id="_1-viper简单介绍"><a href="#_1-viper简单介绍" class="header-anchor">#</a> 1 Viper简单介绍</h2> <h3 id="_1-1-什么是viper"><a href="#_1-1-什么是viper" class="header-anchor">#</a> 1.1 什么是Viper</h3> <div class="custom-block tip"><p class="custom-block-title">Viper介绍</p> <p><code>Viper</code>是<code>Go</code>应用程序的完整配置解决方案，包括<code>12-Factor</code>应用程序。它旨在在应用程序中工作，并可以处理所有类型的配置需求和格式。<code>Viper</code>可以被认为是所有应用程序配置需求的注册表。它支持：</p> <ul><li>设置默认值</li> <li>从<code>JSON，TOML，YAML，HCL</code>和<code>Java</code>属性配置文件中读取</li> <li>实时观看和重新读取配置文件（可选）</li> <li>从环境变量中读取</li> <li>从远程配置系统（<code>etcd</code>或<code>Consul</code>）读取，并观察变化</li> <li>从命令行标志读取</li> <li>从缓冲区读取</li> <li>设置显式值</li></ul></div> <h3 id="_1-2-为何选择viper"><a href="#_1-2-为何选择viper" class="header-anchor">#</a> 1.2 为何选择Viper</h3> <div class="custom-block tip"><p class="custom-block-title">为何选择Viper</p> <p>构建现代应用程序时，您不必担心配置文件格式; 你想专注于构建真棒软件。<code>Viper</code>就是为此提供帮助的。<code>Viper</code>为您做了以下事情：</p> <ul><li>以<code>JSON，TOML，YAML，HCL</code>或<code>Java</code>属性格式查找，加载和解组配置文件。</li> <li>提供一种机制来为不同的配置选项设置默认值。</li> <li>提供一种机制来为通过命令行标志指定的选项设置覆盖值。</li> <li>提供别名系统，轻松重命名参数，而不会破坏现有代码。</li> <li>可以很容易地区分用户提供命令行或配置文件与默认值相同的时间。</li></ul></div> <h3 id="_1-3-配置方式的优先级顺序"><a href="#_1-3-配置方式的优先级顺序" class="header-anchor">#</a> 1.3 配置方式的优先级顺序</h3> <blockquote><p><code>viper</code>提供的配置方式的优先级顺序如下(由高到低)：</p></blockquote> <ul><li>1.设置显示调用(explicit call to Set)</li> <li>2.命令行标志(flag)</li> <li>3.环境变量(env)</li> <li>4.配置文件(config)</li> <li>5.远程键/值存储(key/value store)</li> <li>6.默认值(default)</li></ul> <h2 id="_2-安装及使用"><a href="#_2-安装及使用" class="header-anchor">#</a> 2 安装及使用</h2> <h3 id="_2-1-安装依赖"><a href="#_2-1-安装依赖" class="header-anchor">#</a> 2.1 安装依赖</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">go</span> get github<span class="token punctuation">.</span>com<span class="token operator">/</span>spf13<span class="token operator">/</span>viper
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_2-2-设置默认值"><a href="#_2-2-设置默认值" class="header-anchor">#</a> 2.2 设置默认值</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>viper<span class="token punctuation">.</span><span class="token function">SetDefault</span><span class="token punctuation">(</span><span class="token string">&quot;ContentDir&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;content&quot;</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">SetDefault</span><span class="token punctuation">(</span><span class="token string">&quot;LayoutDir&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;layouts&quot;</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">SetDefault</span><span class="token punctuation">(</span><span class="token string">&quot;Taxonomies&quot;</span><span class="token punctuation">,</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">{</span><span class="token string">&quot;tag&quot;</span><span class="token punctuation">:</span> <span class="token string">&quot;tags&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;category&quot;</span><span class="token punctuation">:</span> <span class="token string">&quot;categories&quot;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="_2-3-读取配置文件"><a href="#_2-3-读取配置文件" class="header-anchor">#</a> 2.3 读取配置文件</h3> <blockquote><p><code>Viper</code>需要最少的配置，因此它知道在哪里查找配置文件。<code>Viper</code>支持<code>JSON，TOML，YAML，HCL</code>和<code>Java Properties</code>文件。<code>Viper</code>可以搜索多个路径，但目前单个<code>Viper</code>实例仅支持单个配置文件。<code>Viper</code>不会默认使用任何配置搜索路径，而是将默认值决定应用于应用程序。
以下是如何使用<code>Viper</code>搜索和读取配置文件的示例,定义在<code>config</code>目录下新建一个<code>appConfig.yaml</code>文件，文件内容如下</p></blockquote> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token comment">#定义一个数据库连接的yaml配置文件测试</span>
<span class="token key atrule">IpAddress</span><span class="token punctuation">:</span> <span class="token string">&quot;127.0.0.1&quot;</span>
<span class="token key atrule">Port</span><span class="token punctuation">:</span> <span class="token number">3306</span>
<span class="token key atrule">UserName</span><span class="token punctuation">:</span> <span class="token string">&quot;root&quot;</span>
<span class="token key atrule">Password</span><span class="token punctuation">:</span> <span class="token number">123456</span>
<span class="token key atrule">DataBaseName</span><span class="token punctuation">:</span> <span class="token string">&quot;go_test&quot;</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;fmt&quot;</span>
	<span class="token string">&quot;github.com/spf13/viper&quot;</span>
<span class="token punctuation">)</span>

<span class="token comment">//定义接收配置文件的结构体</span>
<span class="token keyword">type</span> DataBaseConnection <span class="token keyword">struct</span> <span class="token punctuation">{</span>
	IpAddress    <span class="token builtin">string</span>
	Port         <span class="token builtin">int</span>
	UserName     <span class="token builtin">string</span>
	Password     <span class="token builtin">int</span>
	DataBaseName <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	config <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token comment">//配置文件名（不带扩展名）</span>
	config<span class="token punctuation">.</span><span class="token function">SetConfigName</span><span class="token punctuation">(</span><span class="token string">&quot;appConfig&quot;</span><span class="token punctuation">)</span>
	<span class="token comment">//在项目中查找配置文件的路径，可以使用相对路径，也可以使用绝对路径</span>
	config<span class="token punctuation">.</span><span class="token function">AddConfigPath</span><span class="token punctuation">(</span><span class="token string">&quot;D:/go_project/src/github.com/ourlang/demo/config&quot;</span><span class="token punctuation">)</span>
	<span class="token comment">//多次调用以添加多个搜索路径</span>
	<span class="token comment">//viper.AddConfigPath(&quot;D:/go_project/src/github.com/ourlang/demo/utils&quot;)</span>
	<span class="token comment">//设置文件类型，这里是yaml文件</span>
	config<span class="token punctuation">.</span><span class="token function">SetConfigType</span><span class="token punctuation">(</span><span class="token string">&quot;yaml&quot;</span><span class="token punctuation">)</span>
	<span class="token comment">//定义用于接收配置文件的变量</span>
	<span class="token keyword">var</span> configData DataBaseConnection
	<span class="token comment">//查找并读取配置文件</span>
	err <span class="token operator">:=</span> config<span class="token punctuation">.</span><span class="token function">ReadInConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span> <span class="token comment">// 处理读取配置文件的错误</span>
		<span class="token function">panic</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;Fatal error config file: %s \n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span>

	<span class="token keyword">if</span> err <span class="token operator">:=</span> config<span class="token punctuation">.</span><span class="token function">Unmarshal</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>configData<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span> <span class="token comment">// 读取配置文件转化成对应的结构体错误</span>
		<span class="token function">panic</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;read config file to struct err: %s \n&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span>
	<span class="token comment">//控制台打印输出配置文件读取的值</span>
	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>configData<span class="token punctuation">)</span> <span class="token comment">//{127.0.0.1 3306 root 123456 go_test}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br></div></div><h3 id="_2-4-监听并重新读取配置文件"><a href="#_2-4-监听并重新读取配置文件" class="header-anchor">#</a> 2.4 监听并重新读取配置文件</h3> <blockquote><p><code>Viper</code>支持在运行时让应用程序实时读取配置文件。需要重新启动服务器以使配置生效的日子已经一去不复返了，<code>viper</code>驱动的应用程序可以在运行时读取配置文件的更新，而不会错过任何一个节拍。
只需告诉<code>viper</code>实例<code>watchConfig</code>即可。您可以选择为<code>Viper</code>提供每次发生更改时运行的功能。</p></blockquote> <h4 id="确保在调用之前添加所有configpath-watchconfig"><a href="#确保在调用之前添加所有configpath-watchconfig" class="header-anchor">#</a> 确保在调用之前添加所有<code>configPath WatchConfig()</code></h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code>config <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
config<span class="token punctuation">.</span><span class="token function">WatchConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
config<span class="token punctuation">.</span><span class="token function">OnConfigChange</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span>e fsnotify<span class="token punctuation">.</span>Event<span class="token punctuation">)</span> <span class="token punctuation">{</span>
     <span class="token comment">//viper配置发生变化了 执行响应的操作</span>
	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Config file changed:&quot;</span><span class="token punctuation">,</span> e<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="_2-5-从io-reader读取配置"><a href="#_2-5-从io-reader读取配置" class="header-anchor">#</a> 2.5 从io.Reader读取配置</h3> <blockquote><p><code>Viper</code>预定义了许多配置源，例如文件，环境变量，标志和远程<code>K/V</code>存储，但您不受它们的约束。您还可以实现自己的必需配置源并将其提供给<code>viper</code>。</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;bytes&quot;</span>
	<span class="token string">&quot;fmt&quot;</span>
	<span class="token string">&quot;github.com/spf13/viper&quot;</span>
<span class="token punctuation">)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	config <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	config<span class="token punctuation">.</span><span class="token function">SetConfigType</span><span class="token punctuation">(</span><span class="token string">&quot;yaml&quot;</span><span class="token punctuation">)</span> <span class="token comment">// 或viper.SetConfigType（“YAML”）</span>
	<span class="token comment">//任何需要将此配置放入程序的方法</span>
	<span class="token keyword">var</span> yamlExample <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token function">byte</span><span class="token punctuation">(</span><span class="token string">`
Hacker: true
name: steve
hobbies:
- skateboarding
- snowboarding
- go
clothing:
  jacket: leather
  trousers: denim
age: 35
eyes : brown
beard: true
`</span><span class="token punctuation">)</span>
	<span class="token comment">//读取配置</span>
	config<span class="token punctuation">.</span><span class="token function">ReadConfig</span><span class="token punctuation">(</span>bytes<span class="token punctuation">.</span><span class="token function">NewBuffer</span><span class="token punctuation">(</span>yamlExample<span class="token punctuation">)</span><span class="token punctuation">)</span>

	name <span class="token operator">:=</span> config<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">)</span>
	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><h3 id="_2-6-设置并覆盖配置值"><a href="#_2-6-设置并覆盖配置值" class="header-anchor">#</a> 2.6 设置并覆盖配置值</h3> <div class="language-go line-numbers-mode"><pre class="language-go"><code>config <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
config<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">&quot;Verbose&quot;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
config<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">&quot;LogFile&quot;</span><span class="token punctuation">,</span> LogFile<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="_2-7-注册和使用别名"><a href="#_2-7-注册和使用别名" class="header-anchor">#</a> 2.7 注册和使用别名</h3> <blockquote><p>别名允许多个键引用单个值</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;github.com/spf13/viper&quot;</span>
<span class="token punctuation">)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	config <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	config<span class="token punctuation">.</span><span class="token function">RegisterAlias</span><span class="token punctuation">(</span><span class="token string">&quot;loud&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;Verbose&quot;</span><span class="token punctuation">)</span>
	config<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">&quot;verbose&quot;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token comment">// 结果与下一行相同</span>
	config<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">&quot;loud&quot;</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>    <span class="token comment">// 与上一行相同的结果</span>
	config<span class="token punctuation">.</span><span class="token function">GetBool</span><span class="token punctuation">(</span><span class="token string">&quot;loud&quot;</span><span class="token punctuation">)</span>      <span class="token comment">// true</span>
	config<span class="token punctuation">.</span><span class="token function">GetBool</span><span class="token punctuation">(</span><span class="token string">&quot;verbose&quot;</span><span class="token punctuation">)</span>   <span class="token comment">// true</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="_2-8-使用环境变量"><a href="#_2-8-使用环境变量" class="header-anchor">#</a> 2.8 使用环境变量</h3> <blockquote><p><code>Viper</code>完全支持环境变量。有四种方法可以帮助使用环境变量：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token comment">//AutomaticEnv尤其是当与结合了强大的帮手 SetEnvPrefix。调用时，Viper将在任何viper.Get请求发出时检查环境变量。</span>
<span class="token comment">//它将适用以下规则。它将检查一个环境变量，其名称与大写的键匹配，并以EnvPrefix前缀。</span>
<span class="token function">AutomaticEnv</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">//BindEnv需要一个或两个参数。第一个参数是键名，第二个是环境变量的名称。</span>
<span class="token comment">//环境变量的名称区分大小写。如果未提供ENV变量名，则Viper将自动假设密钥名称与ENV变量名称匹配，但ENV变量为IN ALL CAPS。</span>
<span class="token comment">//当您明确提供ENV变量名称时，它不会自动添加前缀。</span>
<span class="token function">BindEnv</span><span class="token punctuation">(</span><span class="token builtin">string</span><span class="token operator">...</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">error</span>
<span class="token function">SetEnvPrefix</span><span class="token punctuation">(</span><span class="token builtin">string</span><span class="token punctuation">)</span>
<span class="token comment">//SetEnvKeyReplacer允许您使用strings.Replacer对象重写Env键到一定程度。如果要在Get()调用中使用或使用某些内容,</span>
<span class="token comment">//但希望环境变量使用_分隔符，则此选项非常有用。可以在中找到使用它的示例viper_test.go </span>
<span class="token function">SetEnvKeyReplacer</span><span class="token punctuation">(</span><span class="token builtin">string</span><span class="token operator">...</span><span class="token punctuation">)</span> <span class="token operator">*</span>strings<span class="token punctuation">.</span>Replacer
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h4 id="env实例"><a href="#env实例" class="header-anchor">#</a> ENV实例</h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token function">SetEnvPrefix</span><span class="token punctuation">(</span><span class="token string">&quot;spf&quot;</span><span class="token punctuation">)</span>  <span class="token comment">//将自动大写</span>
<span class="token function">BindEnv</span><span class="token punctuation">(</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">)</span>
os<span class="token punctuation">.</span><span class="token function">Setenv</span><span class="token punctuation">(</span><span class="token string">&quot;SPF_ID&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;13&quot;</span><span class="token punctuation">)</span> <span class="token comment">// 通常在应用以外完成</span>
id <span class="token operator">:=</span> <span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">)</span> <span class="token comment">// 13</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h4 id="使用flag"><a href="#使用flag" class="header-anchor">#</a> 使用flag</h4> <blockquote><p><code>Viper</code>能够绑定到<code>flag</code>。就像<code>BindEnv</code>,在调用绑定方法时,不会设置该值。这意味着您可以尽早绑定,甚至可以在<code>init()</code>函数中绑定.
对于单个标志,该<code>BindPFlag()</code>方法提供此功能。</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code>serverCmd<span class="token punctuation">.</span><span class="token function">Flags</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Int</span><span class="token punctuation">(</span><span class="token string">&quot;port&quot;</span><span class="token punctuation">,</span> <span class="token number">1138</span><span class="token punctuation">,</span> <span class="token string">&quot;Port to run Application server on&quot;</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">BindPFlag</span><span class="token punctuation">(</span><span class="token string">&quot;port&quot;</span><span class="token punctuation">,</span> serverCmd<span class="token punctuation">.</span><span class="token function">Flags</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Lookup</span><span class="token punctuation">(</span><span class="token string">&quot;port&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="绑定一组现有的pflags"><a href="#绑定一组现有的pflags" class="header-anchor">#</a> 绑定一组现有的<code>pflags</code></h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code>pflag<span class="token punctuation">.</span><span class="token function">Int</span><span class="token punctuation">(</span><span class="token string">&quot;flagname&quot;</span><span class="token punctuation">,</span> <span class="token number">1234</span><span class="token punctuation">,</span> <span class="token string">&quot;help message for flagname&quot;</span><span class="token punctuation">)</span>
pflag<span class="token punctuation">.</span><span class="token function">Parse</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">BindPFlags</span><span class="token punctuation">(</span>pflag<span class="token punctuation">.</span>CommandLine<span class="token punctuation">)</span>
i <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">GetInt</span><span class="token punctuation">(</span><span class="token string">&quot;flagname&quot;</span><span class="token punctuation">)</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h4 id="flag接口"><a href="#flag接口" class="header-anchor">#</a> flag接口</h4> <blockquote><p>如果您不使用，<code>Viper</code>提供两个<code>Go</code>接口来绑定其他标志系统<code>Pflags</code> <code>FlagValue</code>代表一个标志。这是一个关于如何实现此接口的非常简单的示例：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">type</span> myFlag <span class="token keyword">struct</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
 <span class="token keyword">func</span>  （f  myFlag）HasChanged（）<span class="token builtin">bool</span> <span class="token punctuation">{</span> <span class="token keyword">return</span>  <span class="token boolean">false</span> <span class="token punctuation">}</span>
 <span class="token keyword">func</span>  （f  myFlag）Name（）<span class="token builtin">string</span> <span class="token punctuation">{</span> <span class="token keyword">return</span>  “ my<span class="token operator">-</span>flag<span class="token operator">-</span>name ” <span class="token punctuation">}</span>
 <span class="token keyword">func</span>  （f  myFlag）ValueString（）<span class="token builtin">string</span> <span class="token punctuation">{</span> <span class="token keyword">return</span>  “ my <span class="token operator">-</span>flag<span class="token operator">-</span>value “ <span class="token punctuation">}</span>
 <span class="token keyword">func</span>  （f  myFlag）ValueType（）<span class="token builtin">string</span> <span class="token punctuation">{</span> <span class="token keyword">return</span>  “ <span class="token builtin">string</span> ” <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>一旦你的flag实现了这个接口，你可以告诉Viper绑定它：</p> <div class="language-go line-numbers-mode"><pre class="language-go"><code>viper<span class="token punctuation">.</span><span class="token function">BindFlagValue</span><span class="token punctuation">(</span><span class="token string">&quot;my-flag-name&quot;</span><span class="token punctuation">,</span> myFlag<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_2-9-远程key-value存储"><a href="#_2-9-远程key-value存储" class="header-anchor">#</a> 2.9 远程key/value存储</h3> <blockquote><p><code>Viper</code>可以从例如<code>etcd、Consul</code>的远程<code>Key/Value</code>存储系统的一个路径上,读取一个配置字符串<code>（JSON, TOML, YAML 或 HCL 格式）</code>. 这些值优先于默认值，但会被从磁盘文件、命令行 <code>flag</code>、环境变量的配置所覆盖.要在<code>Viper</code>中启用远程支持，请对<code>viper/remote</code> 包进行空白导入：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token keyword">import</span> <span class="token boolean">_</span> <span class="token string">&quot;github.com/spf13/viper/remote&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="远程key-value存储示例-未加密"><a href="#远程key-value存储示例-未加密" class="header-anchor">#</a> 远程key/value存储示例 - 未加密</h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code>viper<span class="token punctuation">.</span><span class="token function">AddRemoteProvider</span><span class="token punctuation">(</span><span class="token string">&quot;etcd&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;http://127.0.0.1:4001&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;/config/hugo.json&quot;</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">SetConfigType</span><span class="token punctuation">(</span><span class="token string">&quot;json&quot;</span><span class="token punctuation">)</span> <span class="token comment">//因为字节流中没有文件扩展名，支持的扩展名是“json”，“toml”，“yaml”，“yml”，“properties”，“props”，“prop”</span>
err <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">ReadRemoteConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="远程key-value存储示例-加密"><a href="#远程key-value存储示例-加密" class="header-anchor">#</a> 远程key/value存储示例 - 加密</h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code>viper<span class="token punctuation">.</span><span class="token function">AddSecureRemoteProvider</span><span class="token punctuation">(</span><span class="token string">&quot;etcd&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;http://127.0.0.1:4001&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;/config/hugo.json&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;/etc/secrets/mykeyring.gpg&quot;</span><span class="token punctuation">)</span>
viper<span class="token punctuation">.</span><span class="token function">SetConfigType</span><span class="token punctuation">(</span><span class="token string">&quot;json&quot;</span><span class="token punctuation">)</span> <span class="token comment">//因为字节流中没有文件扩展名，支持的扩展名是“json”，“toml”，“yaml”，“yml”，“properties”，“props”，“prop” </span>
err <span class="token operator">:=</span> viper<span class="token punctuation">.</span><span class="token function">ReadRemoteConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="监听etcd中的变化-未加密"><a href="#监听etcd中的变化-未加密" class="header-anchor">#</a> 监听etcd中的变化 - 未加密</h4> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token comment">//或者，您可以创建一个新的viper实例</span>
<span class="token keyword">var</span> runtime_viper <span class="token operator">=</span> viper<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
 
runtime_viper<span class="token punctuation">.</span><span class="token function">AddRemoteProvider</span><span class="token punctuation">(</span><span class="token string">&quot;etcd&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;http://127.0.0.1:4001&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/config/hugo.yml&quot;</span><span class="token punctuation">)</span>
runtime_viper<span class="token punctuation">.</span><span class="token function">SetConfigType</span><span class="token punctuation">(</span><span class="token string">&quot;yaml&quot;</span><span class="token punctuation">)</span>
 
<span class="token comment">// 第一次从远程配置中读取</span>
err <span class="token operator">:=</span> runtime_viper<span class="token punctuation">.</span><span class="token function">ReadRemoteConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
 
<span class="token comment">//解密配置</span>
runtime_viper<span class="token punctuation">.</span><span class="token function">Unmarshal</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>runtime_conf<span class="token punctuation">)</span>
 
<span class="token comment">// 打开一个goroutine来永远监听远程变化</span>
<span class="token keyword">go</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
	<span class="token keyword">for</span> <span class="token punctuation">{</span>
	    time<span class="token punctuation">.</span><span class="token function">Sleep</span><span class="token punctuation">(</span>time<span class="token punctuation">.</span>Second <span class="token operator">*</span> <span class="token number">5</span><span class="token punctuation">)</span> <span class="token comment">// 每次请求后延迟</span>
	    err <span class="token operator">:=</span> runtime_viper<span class="token punctuation">.</span><span class="token function">WatchRemoteConfig</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	    <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
	        log<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;unable to read remote config: %v&quot;</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
	        <span class="token keyword">continue</span>
	    <span class="token punctuation">}</span>
 
	    <span class="token comment">//将新配置解组到我们的运行时配置结构中。您还可以使用通道</span>
        <span class="token comment">//实现信号以通知系统更改 </span>
	    runtime_viper<span class="token punctuation">.</span><span class="token function">Unmarshal</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>runtime_conf<span class="token punctuation">)</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><h2 id="_3-viper获取值"><a href="#_3-viper获取值" class="header-anchor">#</a> 3 Viper获取值</h2> <blockquote><p>在<code>Viper</code>中，有几种方法可以根据值的类型获取值。如果找不到，每个<code>Get</code>函数都将返回零值。<code>IsSet()</code>方法检查给定密钥是否存在。
存在以下功能和方法：</p></blockquote> <div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token function">Get</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token function">GetBool</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">bool</span>
<span class="token function">GetFloat64</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">float64</span>
<span class="token function">GetInt</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">int</span>
<span class="token function">GetString</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">string</span>
<span class="token function">GetStringMap</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token function">GetStringMapString</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span>
<span class="token function">GetStringSlice</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span>
<span class="token function">GetTime</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> time<span class="token punctuation">.</span>Time
<span class="token function">GetDuration</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> time<span class="token punctuation">.</span>Duration
<span class="token function">IsSet</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token builtin">bool</span>
<span class="token function">AllSettings</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h3 id="_3-1-访问嵌套数据"><a href="#_3-1-访问嵌套数据" class="header-anchor">#</a> 3.1 访问嵌套数据</h3> <blockquote><p>访问器方法也接受深层嵌套键的格式化路径。<code>Viper</code>可以通过传递.分隔的键路径来访问嵌套字段。例如，如果加载了以下<code>JSON</code>文件：</p></blockquote> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;host&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;address&quot;</span><span class="token operator">:</span> <span class="token string">&quot;localhost&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">5799</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;datastore&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;metric&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;host&quot;</span><span class="token operator">:</span> <span class="token string">&quot;127.0.0.1&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">3099</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;warehouse&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;host&quot;</span><span class="token operator">:</span> <span class="token string">&quot;198.0.0.1&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;port&quot;</span><span class="token operator">:</span> <span class="token number">2112</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><div class="language-go line-numbers-mode"><pre class="language-go"><code><span class="token function">GetString</span><span class="token punctuation">(</span><span class="token string">&quot;datastore.metric.host&quot;</span><span class="token punctuation">)</span> <span class="token comment">// (returns &quot;127.0.0.1&quot;)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_4-更多参考资料"><a href="#_4-更多参考资料" class="header-anchor">#</a> 4 更多参考资料</h2> <blockquote><p>目前涉及<code>viper</code>的使用大致就是这些了。在应用程序中使用到<code>viper</code>，其灵活的配置选项可以更好地实现容器化部署。并且可以很好适应多种应用场景，让应用程序摆脱配置的束缚。</p></blockquote> <p><a href="https://godoc.org/github.com/spf13/viper" target="_blank" rel="noopener noreferrer">viper API文档<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><a href="https://github.com/spf13/viper" target="_blank" rel="noopener noreferrer">viper源码地址<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/go/middleware/go-swagger.html" class="prev">
        go-swagger安装及使用
      </a></span> <span class="next"><a href="/go/middleware/Goland的自定义快捷键配置.html">
        配置Goland的自定义快捷键
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.1bc80adb.js" defer></script><script src="/assets/js/2.7c0608ab.js" defer></script><script src="/assets/js/93.cf5ff33c.js" defer></script>
  </body>
</html>
